package com.briup.sms.service.impl;

import com.briup.sms.dao.ShopMapper;
import com.briup.sms.entity.Shop;
import com.briup.sms.service.ShopService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author :xuyang
 * @DateTime:2024/1/11 0:25
 * @Version :v1.0.0
 * ClassName:ShopServiceImpl
 * Package  :com.briup.sms.service.impl
 * Description:TODO
 */
@Service
public class ShopServiceImpl implements ShopService {

    @Autowired
    ShopMapper mapper;

    @Override
    public PageInfo<Shop> findShopInfo(String shopName, Integer pageSize, Integer pageNum) {
        List<Shop> List = mapper.findShopInfo(shopName);
        PageInfo<Shop> pageInfo = new PageInfo<>(List);
        return pageInfo;
    }

    @Override
    public void save(Shop shop) {
        //根据shop对象的id是否为空 决定操作
        if (shop.getId() == null) {
            mapper.insertShop(shop);
        } else {
            mapper.updateShop(shop);
        }
    }

    @Override
    public void updateShopStatus(Integer id) {
        //先查id对应的shop的信息
        Shop shop = mapper.findById(id);
        //将启用状态取反
        boolean b = !shop.getStat();
        //赋值给当前对象的启用状态
        shop.setStat(b);
        //更新商品对象信息
        mapper.updateShop(shop);
    }

    @Override
    public Shop getShopInfo(Integer id) {
        return mapper.findById(id);
    }
}
